package com.ruoyi.am.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.am.domain.AmCarPlace;
import com.ruoyi.am.service.IAmCarPlaceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆位置信息Controller
 * 
 * @author hkkk
 * @date 2021-07-03
 */
@Controller
@RequestMapping("/am/place")
public class AmCarPlaceController extends BaseController
{
    private String prefix = "am/place";

    @Autowired
    private IAmCarPlaceService amCarPlaceService;

    @RequiresPermissions("am:place:view")
    @GetMapping()
    public String place()
    {
        return prefix + "/place";
    }

    /**
     * 查询车辆位置信息列表
     */
    @RequiresPermissions("am:place:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AmCarPlace amCarPlace)
    {
        startPage();
        List<AmCarPlace> list = amCarPlaceService.selectAmCarPlaceList(amCarPlace);
        return getDataTable(list);
    }

    /**
     * 导出车辆位置信息列表
     */
    @RequiresPermissions("am:place:export")
    @Log(title = "车辆位置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AmCarPlace amCarPlace)
    {
        List<AmCarPlace> list = amCarPlaceService.selectAmCarPlaceList(amCarPlace);
        ExcelUtil<AmCarPlace> util = new ExcelUtil<AmCarPlace>(AmCarPlace.class);
        return util.exportExcel(list, "place");
    }

    /**
     * 新增车辆位置信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆位置信息
     */
    @RequiresPermissions("am:place:add")
    @Log(title = "车辆位置信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AmCarPlace amCarPlace)
    {
        return toAjax(amCarPlaceService.insertAmCarPlace(amCarPlace));
    }

    /**
     * 修改车辆位置信息
     */
    @GetMapping("/edit/{placeId}")
    public String edit(@PathVariable("placeId") Long placeId, ModelMap mmap)
    {
        AmCarPlace amCarPlace = amCarPlaceService.selectAmCarPlaceById(placeId);
        mmap.put("amCarPlace", amCarPlace);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆位置信息
     */
    @RequiresPermissions("am:place:edit")
    @Log(title = "车辆位置信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AmCarPlace amCarPlace)
    {
        return toAjax(amCarPlaceService.updateAmCarPlace(amCarPlace));
    }

    /**
     * 删除车辆位置信息
     */
    @RequiresPermissions("am:place:remove")
    @Log(title = "车辆位置信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(amCarPlaceService.deleteAmCarPlaceByIds(ids));
    }
}
